﻿/*  
	------------------------------------------------------------------------
	 NQ Core Library
	
	 Homepage: http://www.awzhome.de/
	------------------------------------------------------------------------
	
	This Source Code Form is subject to the terms of the Mozilla Public
	License, v. 2.0. If a copy of the MPL was not distributed with this
	file, You can obtain one at http://mozilla.org/MPL/2.0/.
   
	The Original Code is code of NQ Core Library.

	The Initial Developer of the Original Code is Andreas Weizel.
	Portions created by the Initial Developer are
	Copyright (C) 2012 Andreas Weizel. All Rights Reserved.
	
	Contributor(s): (none)
	
	------------------------------------------------------------------------
*/

using System;

namespace AWZhome.NQ.Core.Fluent
{

	/// <summary>
	/// Wraps a single-instance service instance to be used with the NQ fluent interface.
	/// </summary>
	/// <typeparam name="T">Type of the service instance.</typeparam>
	public class SingleServiceInstanceWrapper<T> : ServiceInstanceWrapper<T>
	{
		internal SingleServiceInstanceWrapper()
			: base()
		{
		}

		/// <summary>
		/// Returns the wrapped service instance.
		/// </summary>
		//[Obsolete("Please use Instance property instead.")]
		public override T To
		{
			get
			{
				return NQServiceManager.Instance.GetService<T>(typeof(T));
			}
		}

		/// <summary>
		/// Returns the wrapped service instance.
		/// </summary>
		public override T Instance
		{
			get
			{
				return NQServiceManager.Instance.GetService<T>(typeof(T));
			}
		}

		/// <summary>
		/// Uses a special type as registered service interface.
		/// </summary>
		/// <param name="serviceInterface">
		/// Registered service
		/// interface as <see cref="System.Type">Type</see> reference.
		/// </param>
		/// <returns>The instance of the wrapper.</returns>
		public virtual ServiceInstanceWrapper<T> UsingInterface(Type serviceInterface)
		{
			return new ServiceInstanceWrapper<T>(NQServiceManager.Instance.GetService<T>(serviceInterface));
		}
	}
}
